home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / contour.arc / SUMMARY.DOC < prev    next >
Text File  |  1991-04-28  |  6KB  |  133 lines

  1.  
  2.  
  3.  
  4.                      Rapid Contour Plots By Bilinear Patch
  5.  
  6.  
  7.      In this technique, the points of the original data array are viewed as
  8.      being samples of a function that is continuous, with piecewise
  9.      continuous partial derivatives.  This function is presumed to be
  10.      bilinear within the squares delineated by the data points.  In order
  11.      to prepare the contour plot of the entire region, we merely prepare a
  12.      contour plot of each square "patch" delineated by four adjacent data
  13.      points.  There is one potential problem with this method, and that is
  14.      if a contour value is exactly equal to one of the data values (one of
  15.      the values exactly on the corner of a patch), then the plot becomes
  16.      ill-conditioned.  In the software example provided, this is readily
  17.      prevented.  The data values take on only integer values, while the
  18.      contour levels are floating point.  We simply prevent any contour
  19.      value from taking on an exact integer value by adding a small number
  20.      (constant called epsilon) if we determine that the contour value is an
  21.      exact integer.
  22.  
  23.      Once this conditioning problem is resolved, it may readily be seen
  24.      that within a single patch, for a specified contour level, exactly
  25.      three possibilities exist:  no contour line crosses the patch,
  26.      determined if the contour level is either less than the minimum of the
  27.      four corner values or greater than the maximum of the corner values;
  28.      one contour line crosses the patch; or two contour lines cross the
  29.      patch.  In the case where one contour line crosses the patch, the
  30.      bilinear equation is solved for the endpoints of the contour line and
  31.      the line is plotted.  In the case where two contour lines cross the
  32.      patch, we determine the four endpoints, and then must decide which
  33.      pairs of endpoints to match to draw the appropriate contour lines.
  34.      Define the bilinear coefficients for the patch in a coordinate system
  35.      local to the patch, so that the x value ranges from 0 to 1 and the y
  36.      value ranges from 0 to 1, and let the bilinear equation be:
  37.  
  38.      value(x,y) = ax + by + cxy +d.
  39.  
  40.      If we now attempt to parametrize the contour line in x in terms of y
  41.      we find:
  42.  
  43.      x = (value - contour level - by - d)/(a + cy).
  44.  
  45.      We then see, that because of the nature of the local coordinate
  46.      system, one of the contour lines must have the y value of both of its
  47.      endpoints greater than -a/c, and the other contour line must have both
  48.      of its endpoints less than -a/c.  (It should be noted that because of
  49.      the non-integral nature of the contour level, we cannot have two
  50.      contour lines in a patch when c=0).  This means that if we simply sort
  51.      the four endpoints in increasing value of their y-values, that the two
  52.      endpoints with the lowest y-values form a pair for one contour line
  53.      and the two endpoints with the highest y-values form a pair for the
  54.      other contour line.
  55.  
  56.      In the software example provided, contour lines are approximated by
  57.      drawing straight lines from one edge of the bilinear patch to the
  58.      other.  In cases where the number of data points are large relative to
  59.      the screen pixel density (say 20 x 20 data points for an EGA display),
  60.      this is adequate for reasonable contour plots.  If the data are
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      sparse, it may be desirable to plot the contour line more accurately
  71.      within the patch, using the parametrized equation above.
  72.  
  73.      The software example provided consists of three modules and one main
  74.      program.  The first module is c_defs.pas and contains the definitions
  75.      used for the contour plotting software, the pointers to the data array
  76.      and the contour level array, and a procedure for allocating memory to
  77.      these arrays.  The data array is called data_array_pointer, which
  78.      points to longint data points, via:  data=data_array_pointer^[x]^[y],
  79.      with 0<=x<max_x_size and 0<=y<max_y_size.  The contour level array
  80.      points to type float (currently set to be single for speed with
  81.      coprocessors), and is accessed via:  contour level = contours^[i],
  82.      with 0<=i<max_contours.  These data arrays are allocated via a call to
  83.      init_array.
  84.  
  85.      The second module is video.pas and contains the routines necessary for
  86.      manipulating the display.  These procedures are:  init_graphics, which
  87.      loads the BGI driver for the graphics display (this procedure requires
  88.      that the Borland BGI driver file for the display be in the default
  89.      directory); close_graphics, which returns the display to text mode;
  90.      and make_line, which plots a single contour line through a single
  91.      patch.  It should be noted, that as written make_line takes as an
  92.      argument the contour number.  The color of the contour line is
  93.      specified by this contour number, so that on EGA and VGA displays, the
  94.      contour plot is color-coded to make it easier to interpret.
  95.  
  96.      The third module is contour.pas and contains the routines necessary
  97.      for contour plotting.  The only procedure available for external
  98.      calling is contour_plot, which performs the entire plot function.
  99.  
  100.      The test program, test.pas, is a skeleton of a general user program
  101.      employing the contour plot modules.  It performs the operations
  102.      minimally necessary for operation.  First, it calls init_array to
  103.      allocate storage.  Then, it fills the data array.  In this example,
  104.      the data array consists of a sum of two two-dimensional Gaussians plus
  105.      noise.  The contour level array is then filled with values (which need
  106.      not be in any particular order).  Init_graphics is called to set the
  107.      display to graphics mode, contour_plot is called to perform the plot,
  108.      and finally close_graphics is called to return the display to text
  109.      mode.
  110.  
  111.      The test package is compiled using the Borland command-line compiler,
  112.      version 5.0, by:  tpc /B test.pas.  All modules internally use
  113.      compiler options $N+ to compile with IEEE floating point and $E+ to
  114.      include the emulator, so that the test program will exhibit identical
  115.      behavior whether a coprocessor is present or not (except for speed).
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.